package com.easy.easylibdemo.ui.imagepicker;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.easylibdemo.R;
import com.easylib.base.BaseActivity;
import com.easylib.utils.ImageLoadUtils;
import com.easylib.utils.ImagePickUtils;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.finalteam.galleryfinal.model.PhotoInfo;

public class ImagePickerActivity extends BaseActivity {

    @Bind(R.id.tv_path)
    TextView tvPath;
    @Bind(R.id.iv_pic)
    ImageView ivPic;

    @Override
    public int getContentViewId() {
        return R.layout.activity_image_picker;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @OnClick({R.id.btn_select, R.id.btn_photo,R.id.iv_pic})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_select:
                ImagePickUtils.openImagePick(1, new ImagePickUtils.ImagePickListener() {
                    @Override
                    public void onHanlderSuccess(int requestCode, List<PhotoInfo> resultList) {
                        tvPath.setText(resultList.get(0).getPhotoPath());
                        ImageLoadUtils.intoForImagePicker(resultList.get(0).getPhotoPath(),ivPic);
                    }

                    @Override
                    public void onHanlderFailure(int requestCode, String errorMsg) {

                    }
                });
                break;
            case R.id.btn_photo:
                ImagePickUtils.openCamera(new ImagePickUtils.ImagePickListener() {
                    @Override
                    public void onHanlderSuccess(int requestCode, List<PhotoInfo> resultList) {
                        tvPath.setText(resultList.get(0).getPhotoPath());
                        ImageLoadUtils.intoForImagePicker(resultList.get(0).getPhotoPath(),ivPic);
                    }

                    @Override
                    public void onHanlderFailure(int requestCode, String errorMsg) {

                    }
                });
                break;
            case R.id.iv_pic:
                tvPath.setText("");
                ivPic.setImageDrawable(null);
                break;
        }
    }
}
